//
//  UIImage+Extension.swift
//  MYWeibo
//
//  Created by Magic Yu on 16/4/22.
//  Copyright © 2016年 Magic Yu. All rights reserved.
//

import UIKit

extension UIImage {

    //给当前屏幕截图
    class func snapShotScreen() -> UIImage {
    
        let window = UIApplication.sharedApplication().keyWindow!
        //开启图片上下文
        UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.mainScreen().scale)
        //将window显示的内容画到上下文中
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        //从上下文中获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        //关闭上下文
        UIGraphicsEndImageContext()
        
        return image
    }
    
}








